package com.laomou.password;

import android.content.Context;
import android.util.Log;
import android.view.accessibility.AccessibilityNodeInfo;

import com.android.acore.task.NodeInfoTask;

public class OnekeyLoginTask extends NodeInfoTask {
	private PasswordHelper mPasswordHelper;
	private Tool mTool;

	@Override
	public void setContext(Context context) {
		super.setContext(context);
		if (mPasswordHelper == null) {
			mPasswordHelper = new PasswordHelper(context);
		}
		if (mTool == null) {
			mTool = new Tool(context);
		}
	}

	@Override
	public void Activity(String className, final AccessibilityNodeInfo view) {
		Log.d("OnekeyLoginTask", className);
		final IPassword password = mPasswordHelper.handlePassword(className);
		if (password != null) {
            mTool.setOneKeyLoginListener(new Tool.OneKeyLoginListener() {
                @Override
                public void OneKeyLogin(boolean login) {
                    AccessibilityNodeInfo accountInfo = findViewId(view, password.getAccountId());
                    if (accountInfo != null) {
                        setText(accountInfo, password.getAccount());
                    }
                    AccessibilityNodeInfo passwordInfo = findViewId(view, password.getPasswordId());
                    if (passwordInfo != null) {
                        setText(passwordInfo, password.getPassword());
                    }
                }
            });
            mTool.show();
        } else {
            mTool.hide();
        }
	}

	@Override
	public void ActivityContent(String className, AccessibilityNodeInfo view) {
	}

	@Override
	public void Notification(String packageName, android.app.Notification notification) {
		
	}

	@Override
	public String getTaskName() {
		return "OnekeyLoginTask";
	}

	@Override
	public boolean isPackage(String packageName) {
		return packageName.equals("com.sina.weibo");
	}

	@Override
	public String getPackageName() {
		return "com.laomou.password";
	}

}
